import java.util.Arrays;


public class SystemCopyVSForLoop {
    public static void main(String[] args) {
        test(false);
        test(false);
        test(false);
        
        test(true);
    }
    
    private static void test(boolean out) {
        int[] arraySizes = new int[] {1000, 100000, 10000000, 100000000};
        for (int size : arraySizes) {
            if (out) System.out.println("Test for size = " + size);
            int[] array = new int[size];
            if (out) System.out.println("System.copy/forLoop = " + (double) getSystemCopy(array) / (double) getForLoop(array));
        }
    }

    private static long getForLoop(int[] array) {
        int[] copy = new int[array.length]; 
        long nanos = System.nanoTime();
        for (int i = 0; i < array.length; ++i) {
            copy[i] = array[i];
        }
        return nanos - System.nanoTime();
    }

    private static long getSystemCopy(int[] array) {
        int[] copy = new int[array.length]; 
        long nanos = System.nanoTime();
        System.arraycopy(array, 0, copy, 0, array.length);
        return nanos - System.nanoTime();
    }
}
